/*TO-DO
 * using the player object passed,
 * update its info after pressing the button "Do it!"
 */
import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

//TODO:make the number of buttons balanced
class ButtonsOfPropHouseHotel extends JPanel implements ActionListener{
	JLabel name;
	JCheckBox propCheckBox;
	JCheckBox utilRailCheckBox;
	JLabel mortgageLabel;//say mortgaged if so
	HouseButton h1, h2, h3, h4;
	HotelButton hotel;
	double cash; //player's cash
	int currentHouseNum;
	//int NumHouse1;
	//int NumHouse2;
	//int NumHouse3;
	int size;
	IntContainer totalGain;
	static double resultCash;
	IntContainer houseNum1, houseNum2, houseNum3;
	BooleanContainer hasHotel1, hasHotel2, hasHotel3;
	BooleanContainer isMortgaged1, isMortgaged2, isMortgaged3;
	Player Player;
	String nameOfProperty;
	int maximumHouseNum;
	JLabel totalLabel;
	JLabel remainingCostLabel;
	int propertyNumber;//set to 0 if we're building on 1st house, 1 for second 
	boolean hasHotel; //if it is true, we cannot anything on the land
	/* p -- Player
	 * colorNum -- # of the properties of the color(2 for darkpurple, 3 for red etc..)
	 * index -- if index is 0, HouseNum1 will be changed, 
	 * totalGain -- of Type Double. its value can be changed from the every ButtonsOfHouseHotel objects
	 * str -- name of the property
	 * numHouse -- starting # of houses of the property
	 * 			   the value is the minimum number of houses.
	 * hasHotel -- return 1 if there is the hotel on the property "at first"
	 * HouseNum1, HouseNum2, HouseNum3 --  
	 */
	
	ButtonsOfPropHouseHotel(Player p, int colorNum, int index, IntContainer totalGain, double cashResult, String str, int numHouse,
			boolean hasHotel, IntContainer HouseNum1, IntContainer HouseNum2, IntContainer HouseNum3, JLabel totalGainLabel,
			JLabel resultLabel, BooleanContainer hasHotel1, BooleanContainer hasHotel2, BooleanContainer hasHotel3, BooleanContainer isMortgaged1,
			BooleanContainer isMortgaged2, BooleanContainer isMortgaged3){
		
		//this.setBackground(Color.lightGray);
		System.out.println("colorNum = " + colorNum);
		size = colorNum;
		this.houseNum1 = HouseNum1;
		this.houseNum2 = HouseNum2;
		this.houseNum3 = HouseNum3;
		this.totalGain = totalGain;
		this.resultCash = cashResult;
		System.out.println(totalGain);
		this.Player = p;
		this.nameOfProperty = str;
		this.maximumHouseNum = numHouse;
		totalLabel = totalGainLabel;
		this.remainingCostLabel = resultLabel;
		propertyNumber = index;
		this.hasHotel1 = hasHotel1;
		this.hasHotel2 = hasHotel2;
		this.hasHotel3 = hasHotel3;
		this.hasHotel = hasHotel;
		this.isMortgaged1 = isMortgaged1;
		this.isMortgaged2 = isMortgaged2;
		this.isMortgaged3 = isMortgaged3;
		
		//determining the currentHouseNum. if the index is 0. the currentHouseNum is the first HouseNumber.
		//pressing the buttons here changes only the value of currentHouseNum
		//changing the value of currentHouseNum will change the value of HouseNum1, HouseNum2, or HouseNum3.
		if(index == 0){
			currentHouseNum = houseNum1.intValue();
		}
		else if(index == 1){
			currentHouseNum = houseNum2.intValue();
		}
		else{
			currentHouseNum = houseNum3.intValue();
		}
		
		
		//create check box that indicates the property is mortgaged or not
		if(index == 0){
			if(this.isMortgaged1.boolValue() == true){
				propCheckBox = new JCheckBox("",true);
				mortgageLabel = new JLabel("Mortgaged");
			}
			else{
				propCheckBox = new JCheckBox("", false);
				mortgageLabel = new JLabel("Not Mortgaged");
			}
		}
		else if(index == 1){
			if(this.isMortgaged2.boolValue() == true){
				propCheckBox = new JCheckBox("",true);
				mortgageLabel = new JLabel("Mortgaged");
			}
			else{
				propCheckBox = new JCheckBox("", false);
				mortgageLabel = new JLabel("Not Mortgaged");
			}
		}
		else{
			if(this.isMortgaged3.boolValue() == true){
				propCheckBox = new JCheckBox("",true);
				mortgageLabel = new JLabel("Mortgaged");
			}
			else{
				propCheckBox = new JCheckBox("", false);
				mortgageLabel = new JLabel("Not Mortgaged");
			}
		}
		
		//create buttons
		name = this.adjustName(str);//str is the name of street
		//propertyButton = new JButton("PROPERTY");
		if(numHouse == 0){
			h1 = new HouseButton("./menuButtons/houseImageClosed.jpg");
			h2 = new HouseButton("./menuButtons/houseImageClosed.jpg");
			h3 = new HouseButton("./menuButtons/houseImageClosed.jpg");
			h4 = new HouseButton("./menuButtons/houseImageClosed.jpg");
			hotel = new HotelButton("./menuButtons/hotelImageClosed.jpg");
		}
		else if(numHouse == 1){
			h1 = new HouseButton("./menuButtons/houseImage.jpg");
			h2 = new HouseButton("./menuButtons/houseImageClosed.jpg");
			h3 = new HouseButton("./menuButtons/houseImageClosed.jpg");
			h4 = new HouseButton("./menuButtons/houseImageClosed.jpg");
			hotel = new HotelButton("./menuButtons/hotelImageClosed.jpg");
		}
		else if(numHouse == 2){
			h1 = new HouseButton("./menuButtons/houseImage.jpg");
			h2 = new HouseButton("./menuButtons/houseImage.jpg");
			h3 = new HouseButton("./menuButtons/houseImageClosed.jpg");
			h4 = new HouseButton("./menuButtons/houseImageClosed.jpg");
			hotel = new HotelButton("./menuButtons/hotelImageClosed.jpg");
		}
		else if(numHouse == 3){
			h1 = new HouseButton("./menuButtons/houseImage.jpg");
			h2 = new HouseButton("./menuButtons/houseImage.jpg");
			h3 = new HouseButton("./menuButtons/houseImage.jpg");
			h4 = new HouseButton("./menuButtons/houseImageClosed.jpg");
			hotel = new HotelButton("./menuButtons/hotelImageClosed.jpg");
		}
		else if(numHouse == 4 && hasHotel == false){
			h1 = new HouseButton("./menuButtons/houseImage.jpg");
			h2 = new HouseButton("./menuButtons/houseImage.jpg");
			h3 = new HouseButton("./menuButtons/houseImage.jpg");
			h4 = new HouseButton("./menuButtons/houseImage.jpg");
			hotel = new HotelButton("./menuButtons/hotelImageClosed.jpg");
		}
		else if(numHouse == 4 && hasHotel == true){
			h1 = new HouseButton("./menuButtons/houseImage.jpg");
			h2 = new HouseButton("./menuButtons/houseImage.jpg");
			h3 = new HouseButton("./menuButtons/houseImage.jpg");
			h4 = new HouseButton("./menuButtons/houseImage.jpg");
			hotel = new HotelButton("./menuButtons/hotelImage.jpg");
		}
		
		
		//make buttons listen
		//propertyButton.addActionListener(this);
		propCheckBox.addActionListener(this);
		h1.addActionListener(this);
		h2.addActionListener(this);
		h3.addActionListener(this);
		h4.addActionListener(this);
		hotel.addActionListener(this);
		
		//panel includes buttons
		add(mortgageLabel);
		add(propCheckBox);
		add(name);
		//add(propertyButton);
		add(h1);
		add(h2);
		add(h3);
		add(h4);
		add(hotel);
	}
	ButtonsOfPropHouseHotel(Player p, int index, IntContainer totalGain, double cashResult, String str, JLabel totalGainLabel,
			JLabel resultLabel, BooleanContainer mortgaged){
		System.out.println("util or railroad");
		this.Player = p;
		propertyNumber = index;
		this.totalGain = totalGain;
		this.resultCash = cashResult;
		System.out.println(totalGain);
		
		this.nameOfProperty = str;
		
		totalLabel = totalGainLabel;
		this.remainingCostLabel = resultLabel;
		
		name = this.adjustName(str);
		isMortgaged1 = mortgaged;

		
		//create check box that indicates the property is mortgaged or not
		
		if(this.isMortgaged1.boolValue() == true){
			System.out.println("its already mortgaged");
			utilRailCheckBox = new JCheckBox("",true);
			utilRailCheckBox.setSelected(true);
			mortgageLabel = new JLabel("Mortgaged");
		}
		else{
			System.out.println("its  not mortgaged");
			utilRailCheckBox = new JCheckBox("", false);
			mortgageLabel = new JLabel("Not Mortgaged");
			utilRailCheckBox.setSelected(false);
		}
		
		
		utilRailCheckBox.addActionListener(this);
		//panel includes buttons
		add(mortgageLabel);
		add(utilRailCheckBox);
		add(name);
		
	}
	public JLabel adjustName(String str){
		JLabel adjustedName = new JLabel();
		if(str == "MediterraneanAve"){
			adjustedName = new JLabel("Mediterranean Avenue");
			adjustedName.setForeground(Color.getHSBColor((float)0.9,(float)0.9,(float)0.7));
		}
		else if (str == "BalticAve"){
			adjustedName = new JLabel("       Baltic Avenue");
			adjustedName.setForeground(Color.getHSBColor((float)0.9,(float)0.9,(float)0.7));
		}
		else if (str == "OrientalAve"){
			adjustedName = new JLabel("     Oriental Avenue");
			adjustedName.setForeground(Color.getHSBColor((float)0.6,(float)1,(float)1));
		}
		else if (str == "VermontAve"){
			adjustedName = new JLabel("      Vermont Avenue");
			adjustedName.setForeground(Color.getHSBColor((float)0.6,(float)1,(float)1));
		}
		else if (str == "ConnecticutAve"){
			adjustedName = new JLabel("  Connecticut Avenue");
			adjustedName.setForeground(Color.getHSBColor((float)0.6,(float)1,(float)1));
		}
		else if (str == "StCharlesPlace"){
			adjustedName = new JLabel("    St.Charles Place");
			adjustedName.setForeground(Color.magenta);
		}
		else if (str == "StatesAve"){
			adjustedName = new JLabel("        States Avenue");
			adjustedName.setForeground(Color.magenta);
		}
		else if (str == "VirginiaAve"){
			adjustedName = new JLabel("     Virginia Avenue");
			adjustedName.setForeground(Color.magenta);
		}
		else if (str == "StJamesPlace"){
			adjustedName = new JLabel("      St.James Place");
			adjustedName.setForeground(Color.orange);
		}
		else if (str == "TennesseeAve"){
			adjustedName = new JLabel("    Tennessee Avenue");
			adjustedName.setForeground(Color.orange);
		}
		else if (str == "NewYorkAve"){
			adjustedName = new JLabel("      NewYork Avenue");
			adjustedName.setForeground(Color.orange);
		}
		else if(str == "KentuckyAve"){
			adjustedName = new JLabel("     Kentucky Avenue");
			adjustedName.setForeground(Color.red);
		}
		else if(str == "IndianaAve"){
			adjustedName = new JLabel("      Indiana Avenue");
			adjustedName.setForeground(Color.red);
		}
		else if(str == "IllinoisAve"){
			adjustedName = new JLabel("     Illinois Avenue");
			adjustedName.setForeground(Color.red);
		}
		else if(str == "AtlanticAve"){
			adjustedName = new JLabel("     Atlantic Avenue");
			adjustedName.setForeground(Color.yellow);
		}
		else if(str == "VentnorAve"){
			adjustedName = new JLabel("      Ventnor Avenue");
			adjustedName.setForeground(Color.yellow);
		}
		else if(str == "MarvinGardens"){
			adjustedName = new JLabel("      Marvin Gardens");
			adjustedName.setForeground(Color.yellow);
		}
		else if(str == "PacificAve"){
			adjustedName = new JLabel("      Pacific Avenue");
			adjustedName.setForeground(Color.green);
		}
		else if(str == "NorthCarolinaAve"){
			adjustedName = new JLabel("NorthCarolina Avenue");
			adjustedName.setForeground(Color.green);
		}
		else if(str == "PennsylvaniaAve"){
			adjustedName = new JLabel(" Pennsylvania Avenue");
			adjustedName.setForeground(Color.green);
		}
		else if(str == "ParkPlace"){
			adjustedName = new JLabel("          Park Place");
			adjustedName.setForeground(Color.blue);
		}
		else if(str == "Boardwalk"){
			adjustedName = new JLabel("           Boardwalk");
			adjustedName.setForeground(Color.blue);
		}
		else if(str == "WaterWorks"){
			adjustedName = new JLabel("Water Works");
			adjustedName.setForeground(Color.darkGray);
		}
		else if(str == "ElectricCompany"){
			adjustedName = new JLabel("Electric Company");
			adjustedName.setForeground(Color.darkGray);
		}
		else if(str == "ReadingRailroad"){
			adjustedName = new JLabel("Reading Railroad");
			adjustedName.setForeground(Color.black);
		}
		else if(str == "B&ORailroad"){
			adjustedName = new JLabel("B&O Railroad");
			adjustedName.setForeground(Color.black);
		}
		else if(str == "ShortLineRailroad"){
			adjustedName = new JLabel("ShortLine Railroad");
			adjustedName.setForeground(Color.black);
		}
		else if(str == "PennsylvaniaRailroad"){
			adjustedName = new JLabel("Pennsylvania Railroad");
			adjustedName.setForeground(Color.black);
		}
		
		return adjustedName;
	}
	public void actionPerformed(ActionEvent e){
		/*if it is true(mortgaged, the player can't do anything for the prop) */
		if(this.Player.isMortgaged(nameOfProperty) == false)
			{
			
			if(e.getSource() == utilRailCheckBox){
				if(this.isMortgaged1.boolValue() == true){
					this.mortgageLabel.setText("Not Mortgaged");
					this.isMortgaged1.setBoolValue(false);
					//utilRailCheckBox.setSelected(false);
					this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getMortgageValue(nameOfProperty));
					this.resultCash -= this.Player.getMortgageValue(nameOfProperty);
					this.totalLabel.setText("Total cost: $" + totalGain.intValue());
					this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
				}
				else{
					
						this.mortgageLabel.setText("Mortgaged");
						this.isMortgaged1.setBoolValue(true);
						//this.isMortgaged1.setBoolValue(true);
						System.out.println("mortgage val = " + this.Player.getMortgageValue(nameOfProperty));
						System.out.println("mortgage val + total gain = " + (this.totalGain.intValue() + this.Player.getMortgageValue(nameOfProperty)));
						this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getMortgageValue(nameOfProperty));
						System.out.println("total gain = " + this.totalGain.intValue());
						this.resultCash += this.Player.getMortgageValue(nameOfProperty);
						this.totalLabel.setText("Total cost: $" + this.totalGain.intValue());
						this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					
					
				}
			}
			
			if(e.getSource() == propCheckBox){
				System.out.println("propNumber: " + this.propertyNumber);
				System.out.println("prop 1 is mortgaged?: " + this.isMortgaged1.boolValue());
				System.out.println("prop 2 is mortgaged?: " + this.isMortgaged2.boolValue());
				System.out.println("houseNum1.intValue(): " + houseNum1.intValue());
				System.out.println("houseNum2.intValue(): " + houseNum2.intValue());
				if(size == 1){
					if(this.isMortgaged1.boolValue() == true)
					{
						this.mortgageLabel.setText("Not Mortgaged");
						this.isMortgaged1.setBoolValue(false);
						propCheckBox.setSelected(false);
						this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getMortgageValue(nameOfProperty));
						this.resultCash -= this.Player.getMortgageValue(nameOfProperty);
						this.totalLabel.setText("Total cost: $" + totalGain.intValue());
						this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					}
				//if this property is temporarily not mortgaged
				//and there are no houses on every props of the same color,
				//The player can mortgage it.
					else{ 
						if(this.isMortgaged1.boolValue() == false){
							this.mortgageLabel.setText("Mortgaged");
							this.isMortgaged1.setBoolValue(true);
							System.out.println("mortgage val = " + this.Player.getMortgageValue(nameOfProperty));
							System.out.println("mortgage val + total gain = " + (this.totalGain.intValue() + this.Player.getMortgageValue(nameOfProperty)));
							this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getMortgageValue(nameOfProperty));
							System.out.println("total gain = " + this.totalGain.intValue());
							this.resultCash += this.Player.getMortgageValue(nameOfProperty);
							this.totalLabel.setText("Total cost: $" + this.totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
						}
					//If, temporarily, it is not mortgaged but there are some houses,
					//then the player cannot mortgage. So checkBox still remains unselected.
						else if(this.isMortgaged1.boolValue() == false){
							this.propCheckBox.setSelected(false);
						}
					}
				}
				if(size == 2){
					
					if(this.propertyNumber == 0){
						//if the prop is "temporarily" mortgaged, the player can cancel the mortgage
						if(this.isMortgaged1.boolValue() == true)
						{
							this.mortgageLabel.setText("Not Mortgaged");
							this.isMortgaged1.setBoolValue(false);
							propCheckBox.setSelected(false);
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getMortgageValue(nameOfProperty));
							this.resultCash -= this.Player.getMortgageValue(nameOfProperty);
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
						}
					//if this property is temporarily not mortgaged
					//and there are no houses on every props of the same color,
					//The player can mortgage it.
						else{ 
							if(this.isMortgaged1.boolValue() == false &&
									this.houseNum1.intValue() == 0 &&
									this.houseNum2.intValue() == 0){
								this.mortgageLabel.setText("Mortgaged");
								this.isMortgaged1.setBoolValue(true);
								System.out.println("mortgage val = " + this.Player.getMortgageValue(nameOfProperty));
								System.out.println("mortgage val + total gain = " + (this.totalGain.intValue() + this.Player.getMortgageValue(nameOfProperty)));
								this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getMortgageValue(nameOfProperty));
								System.out.println("total gain = " + this.totalGain.intValue());
								this.resultCash += this.Player.getMortgageValue(nameOfProperty);
								this.totalLabel.setText("Total cost: $" + this.totalGain.intValue());
								this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
							}
						//If, temporarily, it is not mortgaged but there are some houses,
						//then the player cannot mortgage. So checkBox still remains unselected.
							else if(this.isMortgaged1.boolValue() == false &&
									this.houseNum1.intValue() != 0 ||
									this.houseNum2.intValue() != 0){
								this.propCheckBox.setSelected(false);
							}
						}
					}
					if(this.propertyNumber == 1){
						//if the prop is "temporarily" mortgaged, the player can cancel the mortgage
						if(this.isMortgaged2.boolValue() == true)
						{
							propCheckBox.setSelected(false);
							this.mortgageLabel.setText("Not Mortgaged");
							this.isMortgaged2.setBoolValue(false);
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getMortgageValue(nameOfProperty));
							this.resultCash -= this.Player.getMortgageValue(nameOfProperty);
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
						}
					
						//if this property is temporarily not mortgaged
						//and there are no houses on every props of the same color,
						//The player can mortgage it.
						else{ 
							if(this.isMortgaged2.boolValue() == false &&
									this.houseNum1.intValue() == 0 &&
									this.houseNum2.intValue() == 0){
									this.mortgageLabel.setText("Mortgaged");
									this.isMortgaged2.setBoolValue(true);
									this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getMortgageValue(nameOfProperty));
									this.resultCash += this.Player.getMortgageValue(nameOfProperty);
									this.totalLabel.setText("Total cost: $" + totalGain.intValue());
									this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
							}
							//If, temporarily, it is not mortgaged but there are some houses,
							//then the player cannot mortgage. So checkBox still remains unselected.
							else if(this.isMortgaged2.boolValue() == false &&
									this.houseNum1.intValue() != 0 ||
									this.houseNum2.intValue() != 0){
								this.propCheckBox.setSelected(false);
							}
							
						}
					}	
				}
				if(size == 3){
					if(this.propertyNumber == 0){
						//if the prop is "temporarily" mortgaged, the player can cancel the mortgage
						if(this.isMortgaged1.boolValue() == true)
						{
							this.mortgageLabel.setText("Not Mortgaged");
							this.isMortgaged1.setBoolValue(false);
							propCheckBox.setSelected(false);
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getMortgageValue(nameOfProperty));
							this.resultCash -= this.Player.getMortgageValue(nameOfProperty);
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
						}
						//if this property is temporarily not mortgaged
						//and there are no houses on every props of the same color,
						//The player can mortgage it.
						else{ 
							if(this.isMortgaged1.boolValue() == false &&
									this.houseNum1.intValue() == 0 &&
									this.houseNum2.intValue() == 0 &&
									this.houseNum3.intValue() == 0){
								this.mortgageLabel.setText("Mortgaged");
								this.isMortgaged1.setBoolValue(true);
								
								System.out.println("mortgage val = " + this.Player.getMortgageValue(nameOfProperty));
								System.out.println("mortgage val + total gain = " + (this.totalGain.intValue() + this.Player.getMortgageValue(nameOfProperty)));
								this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getMortgageValue(nameOfProperty));
								System.out.println("total gain = " + this.totalGain.intValue());
								this.resultCash += this.Player.getMortgageValue(nameOfProperty);
								this.totalLabel.setText("Total cost: $" + this.totalGain.intValue());
								this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
							}
							//If, temporarily, it is not mortgaged but there are some houses,
							//then the player cannot mortgage. So checkBox still remains unselected.
							else if(this.isMortgaged1.boolValue() == false &&
									this.houseNum1.intValue() != 0 ||
									this.houseNum2.intValue() != 0 ||
									this.houseNum3.intValue() != 0){
								this.propCheckBox.setSelected(false);
							}
							
						}
					}
					if(this.propertyNumber == 1){
						//if the prop is "temporarily" mortgaged, the player can cancel the mortgage
						if(this.isMortgaged2.boolValue() == true)
						{
							this.mortgageLabel.setText("Not Mortgaged");
							this.isMortgaged2.setBoolValue(false);
							propCheckBox.setSelected(false);
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getMortgageValue(nameOfProperty));
							this.resultCash -= this.Player.getMortgageValue(nameOfProperty);
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
						}
						//if this property is temporarily not mortgaged
						//and there are no houses on every props of the same color,
						//The player can mortgage it.
						else{ 
							if(this.isMortgaged2.boolValue() == false &&
									this.houseNum1.intValue() == 0 &&
									this.houseNum2.intValue() == 0 &&
									this.houseNum3.intValue() == 0){
								this.mortgageLabel.setText("Mortgaged");
								this.isMortgaged2.setBoolValue(true);
								
								System.out.println("mortgage val = " + this.Player.getMortgageValue(nameOfProperty));
								System.out.println("mortgage val + total gain = " + (this.totalGain.intValue() + this.Player.getMortgageValue(nameOfProperty)));
								this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getMortgageValue(nameOfProperty));
								System.out.println("total gain = " + this.totalGain.intValue());
								this.resultCash += this.Player.getMortgageValue(nameOfProperty);
								this.totalLabel.setText("Total cost: $" + this.totalGain.intValue());
								this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
							}
							//If, temporarily, it is not mortgaged but there are some houses,
							//then the player cannot mortgage. So checkBox still remains unselected.
							else if(this.isMortgaged2.boolValue() == false &&
									this.houseNum1.intValue() != 0 ||
									this.houseNum2.intValue() != 0 ||
									this.houseNum3.intValue() != 0){
								this.propCheckBox.setSelected(false);
							}
						}
					}
					if(this.propertyNumber == 2){
						//if the prop is "temporarily" mortgaged, the player can cancel the mortgage
						if(this.isMortgaged3.boolValue() == true)
						{
							this.mortgageLabel.setText("Not Mortgaged");
							this.isMortgaged3.setBoolValue(false);
							propCheckBox.setSelected(false);
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getMortgageValue(nameOfProperty));
							this.resultCash -= this.Player.getMortgageValue(nameOfProperty);
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
						}
						//if this property is temporarily not mortgaged
						//and there are no houses on every props of the same color,
						//The player can mortgage it.
						else{ 
							if(this.isMortgaged3.boolValue() == false &&
									this.houseNum1.intValue() == 0 &&
									this.houseNum2.intValue() == 0 &&
									this.houseNum3.intValue() == 0){
								this.mortgageLabel.setText("Mortgaged");
								this.isMortgaged3.setBoolValue(true);
								
								System.out.println("mortgage val = " + this.Player.getMortgageValue(nameOfProperty));
								System.out.println("mortgage val + total gain = " + (this.totalGain.intValue() + this.Player.getMortgageValue(nameOfProperty)));
								this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getMortgageValue(nameOfProperty));
								System.out.println("total gain = " + this.totalGain.intValue());
								this.resultCash += this.Player.getMortgageValue(nameOfProperty);
								this.totalLabel.setText("Total cost: $" + this.totalGain.intValue());
								this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
							}
							//If, temporarily, it is not mortgaged but there are some houses,
							//then the player cannot mortgage. So checkBox still remains unselected.
							else if(this.isMortgaged3.boolValue() == false &&
									this.houseNum1.intValue() != 0 ||
									this.houseNum2.intValue() != 0 ||
									this.houseNum3.intValue() != 0){
								this.propCheckBox.setSelected(false);
							}
						}
					}
				}
			}
		
			if(e.getSource() == h1){//when pressing button h1
				//CASE1: There are 2 properties of the color
				if(size == 2){
					if(this.propertyNumber == 0)
					{
						//we can't build the first building if there already exists the house(can do only when currentHouseNum is 0). 
						//if there is no house && the difference of these 2 houses is less than 2, we can build
						//&& the resulting cost doesnt exceed the player's cash
						if( currentHouseNum == 0 && 
								currentHouseNum+1 <= this.maximumHouseNum &&
								Math.abs(((currentHouseNum+1) - this.houseNum2.intValue())) <= 1 &&
								this.isMortgaged1.boolValue() == false &&
								this.isMortgaged2.boolValue() == false &&
								this.isMortgaged3.boolValue() == false)
						{
							
							this.currentHouseNum++;
							System.out.println(this.currentHouseNum);//test
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							h1.changeImageToBuilt();//change the image to built
							
						
							this.houseNum1.increment();
							
						
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + resultCash);
						}
						//or we can deselect it when there is only one house on the property.
						//&& it keeps the differece of houseNum <= 1
						//&& the resulting currentHouseNum won't be less than the minimum HouseNum
						else if((currentHouseNum == 1) &&
								Math.abs(((currentHouseNum-1) - this.houseNum2.intValue())) <= 1
								){

								this.currentHouseNum--;
								System.out.println(this.currentHouseNum);//test
								this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
								this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
							
								h1.changeImageToSale();
								//update the houseNumber
							
								this.houseNum1.decrement();
							
								this.totalLabel.setText("Total cost: $" + totalGain.intValue());
								this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
							}
					}
					else if(this.propertyNumber == 1){
					
					//we can't build the first building if there already exists the house(can do only when currentHouseNum is 0). 
					//if there is no house && the difference of these 2 houses is less than 2, we can build
					//&& the resulting cost doesnt exceed the player's cash
					if( currentHouseNum == 0 && 
							currentHouseNum+1 <= this.maximumHouseNum &&
							Math.abs(((currentHouseNum+1) - this.houseNum1.intValue())) <= 1 &&
							this.isMortgaged1.boolValue() == false &&
							this.isMortgaged2.boolValue() == false &&
							this.isMortgaged3.boolValue() == false)
					{
							
							this.currentHouseNum++;
							System.out.println(this.currentHouseNum);//test
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							h1.changeImageToBuilt();
						
							this.houseNum2.increment();
						
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + resultCash);
					}
					//or we can deselect it when there is only one house on the property.
					//&& it keeps the differece of houseNum <= 1
					//&& the resulting currentHouseNum won't be less than the minimum HouseNum
					else if((currentHouseNum == 1) &&
							Math.abs(((currentHouseNum-1) - this.houseNum1.intValue())) <= 1 
							){
							
							this.currentHouseNum--;
							System.out.println(this.currentHouseNum);//test
							this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
							
							h1.changeImageToSale();
							//update the houseNumber
							
							this.houseNum2.decrement();
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
						}
				}
			}
			//CASE2: There are 3 properties of the color
			else if(size == 3){
				if(this.propertyNumber == 0){
					System.out.println("currentHouseNum: " + currentHouseNum + "House2: "+ houseNum2.intValue() + "house3: " + houseNum3.intValue());//test
					
					//if there is no house && the difference of these 2 houses is less than 2, we can build
					//&& the resulting cost doesnt exceed the player's cash
					if( currentHouseNum == 0 && 
							currentHouseNum+1 <= this.maximumHouseNum &&
							Math.abs(((currentHouseNum+1) - this.houseNum2.intValue())) <= 1 &&
							Math.abs(((currentHouseNum+1) - this.houseNum3.intValue())) <= 1 &&
							this.isMortgaged1.boolValue() == false &&
							this.isMortgaged2.boolValue() == false &&
							this.isMortgaged3.boolValue() == false)
					{
							h1.changeImageToBuilt();
							this.currentHouseNum++;
							System.out.println("Build. House1: "+ houseNum1.intValue() + "house2: " + houseNum2.intValue() + "currentHouseNum: " + currentHouseNum);//test
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							//update the houseNumber
							
							this.houseNum1.increment();
							System.out.println("houseNum1 = " + houseNum1.intValue());
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					}
					//or we can deselect it when there is only one house on the property.
					else if((currentHouseNum == 1) &&
							Math.abs(((currentHouseNum-1) - this.houseNum2.intValue())) <= 1 &&
							Math.abs(((currentHouseNum-1) - this.houseNum3.intValue())) <= 1 
							)
					{
							h1.changeImageToSale();
							this.currentHouseNum--;
							System.out.println("Sold. currentHouseNum is : " + currentHouseNum +" house2: "+ houseNum2.intValue() + " house3: " + houseNum3.intValue());//test
							this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
							
							//update the houseNumber
							
								this.houseNum1.decrement();
								System.out.println("houseNum1 = " + houseNum1.intValue());
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					}
				}
				else if(this.propertyNumber == 1){
					System.out.println("House1: "+ houseNum1.intValue() + "housenum2: " + currentHouseNum + " house3: " + houseNum3.intValue());//test
					
					//if there is no house && the difference of these 2 houses is less than 2, we can build
					//&& the resulting cost doesnt exceed the player's cash
					if( currentHouseNum == 0 && 
							currentHouseNum+1 <= this.maximumHouseNum &&
							Math.abs(((currentHouseNum+1) - this.houseNum1.intValue())) <= 1 &&
							Math.abs(((currentHouseNum+1) - this.houseNum3.intValue())) <= 1 &&
							this.isMortgaged1.boolValue() == false &&
							this.isMortgaged2.boolValue() == false &&
							this.isMortgaged3.boolValue() == false)
					{
							h1.changeImageToBuilt();
							this.currentHouseNum++;
							System.out.println("Build. House1: "+ houseNum1.intValue() + "house2: " + houseNum2.intValue() + "currentHouseNum: " + currentHouseNum);//test
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							//update the houseNumber
							
								this.houseNum2.increment();
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					}
					//or we can deselect it when there is only one house on the property.
					else if((currentHouseNum == 1) &&
							Math.abs(((currentHouseNum-1) - this.houseNum1.intValue())) <= 1 &&
							Math.abs(((currentHouseNum-1) - this.houseNum3.intValue())) <= 1 
							)
					{
							h1.changeImageToSale();
							this.currentHouseNum--;
							System.out.println("Sold. currentHouseNum is : " + currentHouseNum +" house1: "+ houseNum1.intValue() + " house3: " + houseNum3.intValue());//test
							this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
							
							//update the houseNumber
							
								this.houseNum2.decrement();
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					}
				}
				else if(this.propertyNumber == 2){
					System.out.println("House1: "+ houseNum1.intValue() + "house2: " + houseNum2.intValue() + "currentHouseNum: " + currentHouseNum);//test
					
					//if there is no house && the difference of these 2 houses is less than 2, we can build
					//&& the resulting cost doesnt exceed the player's cash
					if( currentHouseNum == 0 && 
							currentHouseNum+1 <= this.maximumHouseNum &&
							Math.abs(((currentHouseNum+1) - this.houseNum1.intValue())) <= 1 &&
							Math.abs(((currentHouseNum+1) - this.houseNum2.intValue())) <= 1 &&
							this.isMortgaged1.boolValue() == false &&
							this.isMortgaged2.boolValue() == false &&
							this.isMortgaged3.boolValue() == false)
					{
							h1.changeImageToBuilt();
							this.currentHouseNum++;
							System.out.println("Build. House1: "+ houseNum1.intValue() + "house2: " + houseNum2.intValue() + "currentHouseNum: " + currentHouseNum);//test
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							//update the houseNumber
							
								this.houseNum3.increment();
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					}
					//or we can deselect it when there is only one house on the property.
					else if((currentHouseNum == 1) &&
							Math.abs(((currentHouseNum-1) - this.houseNum1.intValue())) <= 1 &&
							Math.abs(((currentHouseNum-1) - this.houseNum2.intValue())) <= 1 
							)
					{
							h1.changeImageToSale();
							this.currentHouseNum--;
							System.out.println("Sold. currentHouseNum is : " + currentHouseNum +" house1: "+ houseNum1.intValue() + " house2: " + houseNum2.intValue());//test
							this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
							
							//update the houseNumber
							
								this.houseNum3.decrement();
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					}
				}
			}
		}
		
		if(e.getSource() == h2){
			//CASE1: There are 2 properties of the color
			if(size == 2){
				if(this.propertyNumber == 0){
					//we can't build the first building if there already exists 2 houses(can do only when currentHouseNum is 1). 
					//if there is no house && the difference of these 2 houses is less than 2, we can build
					//&& the resulting cost doesnt exceed the player's cash
					if( currentHouseNum == 1 && 
							currentHouseNum+1 <= this.maximumHouseNum &&
							Math.abs(((currentHouseNum+1) - this.houseNum2.intValue())) <= 1 
							)
					{
							h2.changeImageToBuilt();
							this.currentHouseNum++;
							System.out.println(this.currentHouseNum);//test
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							//update the houseNumber
							
							this.houseNum1.increment();
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + resultCash);
					}
					//or we can deselect it when there is only one house on the property.
					//&& it keeps the differece of houseNum <= 1
					//&& the resulting currentHouseNum won't be less than the minimum HouseNum
					else if((currentHouseNum == 2) &&
							Math.abs(((currentHouseNum-1) - this.houseNum2.intValue())) <= 1 
							){
								h2.changeImageToSale();
								this.currentHouseNum--;
								System.out.println(this.currentHouseNum);//test
								this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
								this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
								
								
									this.houseNum1.decrement();
								
								this.totalLabel.setText("Total cost: $" + totalGain.intValue());
								this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
							}
					}
				else if(this.propertyNumber == 1){
					//we can't build the first building if there already exists 2 houses(can do only when currentHouseNum is 1). 
					//if there is no house && the difference of these 2 houses is less than 2, we can build
					//&& the resulting cost doesnt exceed the player's cash
					if( currentHouseNum == 1 && 
							currentHouseNum+1 <= this.maximumHouseNum &&
							Math.abs(((currentHouseNum+1) - this.houseNum1.intValue())) <= 1 
							)
					{
							h2.changeImageToBuilt();
							this.currentHouseNum++;
							System.out.println(this.currentHouseNum);//test
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							//update the houseNumber
							
							this.houseNum2.increment();
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + resultCash);
					}
					//or we can deselect it when there is only one house on the property.
					//&& it keeps the differece of houseNum <= 1
					//&& the resulting currentHouseNum won't be less than the minimum HouseNum
					else if((currentHouseNum == 2) &&
							Math.abs(((currentHouseNum-1) - this.houseNum1.intValue())) <= 1 
							){
								h2.changeImageToSale();
								this.currentHouseNum--;
								System.out.println(this.currentHouseNum);//test
								this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
								this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
								
								
								this.houseNum2.decrement();
								
								this.totalLabel.setText("Total cost: $" + totalGain.intValue());
								this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					}
				}
			}
			//CASE2: There are 3 properties of the color
			else if(size == 3){
				if(this.propertyNumber == 0){
					//if there is no house && the difference of these 2 houses is less than 2, we can build
					//&& the resulting cost doesnt exceed the player's cash
					if( currentHouseNum == 1 && 
							currentHouseNum+1 <= this.maximumHouseNum &&
							Math.abs(((currentHouseNum+1) - this.houseNum2.intValue())) <= 1 &&
							Math.abs(((currentHouseNum+1) - this.houseNum3.intValue())) <= 1 
							)
						{
							h2.changeImageToBuilt();
							this.currentHouseNum++;
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							
							this.houseNum1.increment();
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
						}
					//or we can deselect it when there is only one house on the property.
					else if((currentHouseNum == 2) &&
							Math.abs(((currentHouseNum-1) - this.houseNum2.intValue())) <= 1 &&
							Math.abs(((currentHouseNum-1) - this.houseNum3.intValue())) <= 1 
							)
					{
							h2.changeImageToSale();
							this.currentHouseNum--;
							this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
							
							
							
							this.houseNum1.decrement();
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					}
				}
				else if(this.propertyNumber == 1){
					//if there is no house && the difference of these 2 houses is less than 2, we can build
					//&& the resulting cost doesnt exceed the player's cash
					if( currentHouseNum == 1 && 
							currentHouseNum+1 <= this.maximumHouseNum &&
							Math.abs(((currentHouseNum+1) - this.houseNum1.intValue())) <= 1 &&
							Math.abs(((currentHouseNum+1) - this.houseNum3.intValue())) <= 1 
							)
						{
							h2.changeImageToBuilt();
							this.currentHouseNum++;
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							
							
							this.houseNum2.increment();
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
						}
					//or we can deselect it when there is only one house on the property.
					else if((currentHouseNum == 2) &&
							Math.abs(((currentHouseNum-1) - this.houseNum2.intValue())) <= 1 &&
							Math.abs(((currentHouseNum-1) - this.houseNum3.intValue())) <= 1 
							)
					{
							h2.changeImageToSale();
							this.currentHouseNum--;
							this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
							
							
							
							this.houseNum2.decrement();
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					}
				}
				else if(this.propertyNumber == 2){
					//if there is no house && the difference of these 2 houses is less than 2, we can build
					//&& the resulting cost doesnt exceed the player's cash
					if( currentHouseNum == 1 && 
							currentHouseNum+1 <= this.maximumHouseNum &&
							Math.abs(((currentHouseNum+1) - this.houseNum1.intValue())) <= 1 &&
							Math.abs(((currentHouseNum+1) - this.houseNum2.intValue())) <= 1 
							)
						{
							h2.changeImageToBuilt();
							this.currentHouseNum++;
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							
							
							this.houseNum3.increment();
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
						}
					//or we can deselect it when there is only one house on the property.
					else if((currentHouseNum == 2) &&
							Math.abs(((currentHouseNum-1) - this.houseNum1.intValue())) <= 1 &&
							Math.abs(((currentHouseNum-1) - this.houseNum2.intValue())) <= 1
							)
					{
							h2.changeImageToSale();
							this.currentHouseNum--;
							this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
							
							
							
							this.houseNum3.decrement();
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					}
				}
			}
		}
		if(e.getSource() == h3){
			//CASE1: There are 2 properties of the color
			if(size == 2){
				if(this.propertyNumber == 0){
					//we can't build the first building if there already exists 2 houses(can do only when currentHouseNum is 1). 
					//if there is no house && the difference of these 2 houses is less than 2, we can build
					//&& the resulting cost doesnt exceed the player's cash
					if( currentHouseNum == 2 && 
							currentHouseNum+1 <= this.maximumHouseNum &&
							Math.abs(((currentHouseNum+1) - this.houseNum2.intValue())) <= 1 
							)
					{
							h3.changeImageToBuilt();
							this.currentHouseNum++;
							System.out.println(this.currentHouseNum);//test
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							//update the houseNumber
							
							this.houseNum1.increment();
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + resultCash);
					}
					//or we can deselect it when there is only one house on the property.
					//&& it keeps the differece of houseNum <= 1
					//&& the resulting currentHouseNum won't be less than the minimum HouseNum
					else if((currentHouseNum == 3) &&
							Math.abs(((currentHouseNum-1) - this.houseNum2.intValue())) <= 1 
							){
								h3.changeImageToSale();
								this.currentHouseNum--;
								System.out.println(this.currentHouseNum);//test
								this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
								this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
								
								
									this.houseNum1.decrement();
								
								this.totalLabel.setText("Total cost: $" + totalGain.intValue());
								this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
							}
					}
				else if(this.propertyNumber == 1){
					//we can't build the first building if there already exists 2 houses(can do only when currentHouseNum is 1). 
					//if there is no house && the difference of these 2 houses is less than 2, we can build
					//&& the resulting cost doesnt exceed the player's cash
					if( currentHouseNum == 2 && 
							currentHouseNum+1 <= this.maximumHouseNum &&
							Math.abs(((currentHouseNum+1) - this.houseNum1.intValue())) <= 1 
							)
					{
							h3.changeImageToBuilt();
							this.currentHouseNum++;
							System.out.println(this.currentHouseNum);//test
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							//update the houseNumber
							
							this.houseNum2.increment();
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + resultCash);
					}
					//or we can deselect it when there is only one house on the property.
					//&& it keeps the differece of houseNum <= 1
					//&& the resulting currentHouseNum won't be less than the minimum HouseNum
					else if((currentHouseNum == 3) &&
							Math.abs(((currentHouseNum-1) - this.houseNum1.intValue())) <= 1 
							){
								h3.changeImageToSale();
								this.currentHouseNum--;
								System.out.println(this.currentHouseNum);//test
								this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
								this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
								
								
								this.houseNum2.decrement();
								
								this.totalLabel.setText("Total cost: $" + totalGain.intValue());
								this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					}
				}
			}
			//CASE2: There are 3 properties of the color
			else if(size == 3){
				if(this.propertyNumber == 0){
					//if there is no house && the difference of these 2 houses is less than 2, we can build
					//&& the resulting cost doesnt exceed the player's cash
					if( currentHouseNum == 2 && 
							currentHouseNum+1 <= this.maximumHouseNum &&
							Math.abs(((currentHouseNum+1) - this.houseNum2.intValue())) <= 1 &&
							Math.abs(((currentHouseNum+1) - this.houseNum3.intValue())) <= 1 
							)
						{
							h3.changeImageToBuilt();
							this.currentHouseNum++;
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							this.houseNum1.increment();
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
						}
					//or we can deselect it when there is only one house on the property.
					else if((currentHouseNum == 3) &&
							Math.abs(((currentHouseNum-1) - this.houseNum2.intValue())) <= 1 &&
							Math.abs(((currentHouseNum-1) - this.houseNum3.intValue())) <= 1 
							)
					{
							h3.changeImageToSale();
							this.currentHouseNum--;
							this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
							
							
							
							this.houseNum1.decrement();
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					}
				}
				else if(this.propertyNumber == 1){
					//if there is no house && the difference of these 2 houses is less than 2, we can build
					//&& the resulting cost doesnt exceed the player's cash
					if( currentHouseNum == 2 && 
							currentHouseNum+1 <= this.maximumHouseNum &&
							Math.abs(((currentHouseNum+1) - this.houseNum1.intValue())) <= 1 &&
							Math.abs(((currentHouseNum+1) - this.houseNum3.intValue())) <= 1 
							)
						{
							h3.changeImageToBuilt();
							this.currentHouseNum++;
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							
							
							this.houseNum2.increment();
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
						}
					//or we can deselect it when there is only one house on the property.
					else if((currentHouseNum == 3) &&
							Math.abs(((currentHouseNum-1) - this.houseNum2.intValue())) <= 1 &&
							Math.abs(((currentHouseNum-1) - this.houseNum3.intValue())) <= 1 
							)
					{
							h3.changeImageToSale();
							this.currentHouseNum--;
							this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
							
							
							
							this.houseNum2.decrement();
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					}
				}
				else if(this.propertyNumber == 2){
					//if there is no house && the difference of these 2 houses is less than 2, we can build
					//&& the resulting cost doesnt exceed the player's cash
					if( currentHouseNum == 2 && 
							currentHouseNum+1 <= this.maximumHouseNum &&
							Math.abs(((currentHouseNum+1) - this.houseNum1.intValue())) <= 1 &&
							Math.abs(((currentHouseNum+1) - this.houseNum2.intValue())) <= 1 
							)
						{
							h3.changeImageToBuilt();
							this.currentHouseNum++;
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							
							
							this.houseNum3.increment();
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
						}
					//or we can deselect it when there is only one house on the property.
					else if((currentHouseNum == 3) &&
							Math.abs(((currentHouseNum-1) - this.houseNum1.intValue())) <= 1 &&
							Math.abs(((currentHouseNum-1) - this.houseNum2.intValue())) <= 1 
							)
					{
							h3.changeImageToSale();
							this.currentHouseNum--;
							this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
							
							
							
							this.houseNum3.decrement();
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					}
				}
			}
		}
		
		if(e.getSource() == h4){
			//CASE1: There are 2 properties of the color
			if(size == 2){
				if(this.propertyNumber == 0){
					//we can't build the first building if there already exists 2 houses(can do only when currentHouseNum is 1). 
					//if there is no house && the difference of these 2 houses is less than 2, we can build
					//&& the resulting cost doesnt exceed the player's cash
					if( currentHouseNum == 3 && 
							currentHouseNum+1 <= this.maximumHouseNum &&
							Math.abs(((currentHouseNum+1) - this.houseNum2.intValue())) <= 1 
							)
					{
							h4.changeImageToBuilt();
							this.currentHouseNum++;
							System.out.println(this.currentHouseNum);//test
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							//update the houseNumber
							
							this.houseNum1.increment();
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + resultCash);
					}
					//or we can deselect it when there is only one house on the property.
					//&& it keeps the differece of houseNum <= 1
					//&& the resulting currentHouseNum won't be less than the minimum HouseNum
					else if((currentHouseNum == 4) &&
							this.hasHotel1.boolValue() == false &&
							this.hasHotel2.boolValue() == false &&
							Math.abs(((currentHouseNum-1) - this.houseNum2.intValue())) <= 1 
							){
								h4.changeImageToSale();
								this.currentHouseNum--;
								System.out.println(this.currentHouseNum);//test
								this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
								this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
								
								
									this.houseNum1.decrement();
								
								this.totalLabel.setText("Total cost: $" + totalGain.intValue());
								this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
							}
					}
				else if(this.propertyNumber == 1){
					//we can't build the first building if there already exists 2 houses(can do only when currentHouseNum is 1). 
					//if there is no house && the difference of these 2 houses is less than 2, we can build
					//&& the resulting cost doesnt exceed the player's cash
					if( currentHouseNum == 3 && 
							currentHouseNum+1 <= this.maximumHouseNum &&
							Math.abs(((currentHouseNum+1) - this.houseNum1.intValue())) <= 1 
							)
					{
							h4.changeImageToBuilt();
							this.currentHouseNum++;
							System.out.println(this.currentHouseNum);//test
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							//update the houseNumber
							
							this.houseNum2.increment();
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + resultCash);
					}
					//or we can deselect it when there is only one house on the property.
					//&& it keeps the differece of houseNum <= 1
					//&& the resulting currentHouseNum won't be less than the minimum HouseNum
					else if((currentHouseNum == 4) &&
							this.hasHotel1.boolValue() == false &&
							this.hasHotel2.boolValue() == false &&
							Math.abs(((currentHouseNum-1) - this.houseNum1.intValue())) <= 1 
							){
								h4.changeImageToSale();
								this.currentHouseNum--;
								System.out.println(this.currentHouseNum);//test
								this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
								this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
								
								
								this.houseNum2.decrement();
								
								this.totalLabel.setText("Total cost: $" + totalGain.intValue());
								this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					}
				}
			}
			//CASE2: There are 3 properties of the color
			else if(size == 3){
				if(this.propertyNumber == 0){
					//if there is no house && the difference of these 2 houses is less than 2, we can build
					//&& the resulting cost doesnt exceed the player's cash
					if( currentHouseNum == 3 && 
							currentHouseNum+1 <= this.maximumHouseNum &&
							Math.abs(((currentHouseNum+1) - this.houseNum2.intValue())) <= 1 &&
							Math.abs(((currentHouseNum+1) - this.houseNum3.intValue())) <= 1 
							)
						{
							h4.changeImageToBuilt();
							this.currentHouseNum++;
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							
							this.houseNum1.increment();
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
						}
					//or we can deselect it when there is only one house on the property.
					else if((currentHouseNum == 4) &&
							this.hasHotel1.boolValue() == false &&
							this.hasHotel2.boolValue() == false &&
							this.hasHotel3.boolValue() == false &&
							Math.abs(((currentHouseNum-1) - this.houseNum2.intValue())) <= 1 &&
							Math.abs(((currentHouseNum-1) - this.houseNum3.intValue())) <= 1 
							)
					{
							h4.changeImageToSale();
							this.currentHouseNum--;
							this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
							
							
							
							this.houseNum1.decrement();
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					}
				}
				else if(this.propertyNumber == 1){
					//if there is no house && the difference of these 2 houses is less than 2, we can build
					//&& the resulting cost doesnt exceed the player's cash
					if( currentHouseNum == 3 && 
							currentHouseNum+1 <= this.maximumHouseNum &&
							Math.abs(((currentHouseNum+1) - this.houseNum1.intValue())) <= 1 &&
							Math.abs(((currentHouseNum+1) - this.houseNum3.intValue())) <= 1 
							)
						{
							h4.changeImageToBuilt();
							this.currentHouseNum++;
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							
							
							this.houseNum2.increment();
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
						}
					//or we can deselect it when there is only one house on the property.
					else if((currentHouseNum == 4) &&
							this.hasHotel1.boolValue() == false &&
							this.hasHotel2.boolValue() == false &&
							this.hasHotel3.boolValue() == false &&
							Math.abs(((currentHouseNum-1) - this.houseNum2.intValue())) <= 1 &&
							Math.abs(((currentHouseNum-1) - this.houseNum3.intValue())) <= 1 
							)
					{
							h4.changeImageToSale();
							this.currentHouseNum--;
							this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
							
							
							
							this.houseNum2.decrement();
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					}
				}
				else if(this.propertyNumber == 2){
					//if there is no house && the difference of these 2 houses is less than 2, we can build
					//&& the resulting cost doesnt exceed the player's cash
					if( currentHouseNum == 3 && 
							currentHouseNum+1 <= this.maximumHouseNum &&
							Math.abs(((currentHouseNum+1) - this.houseNum1.intValue())) <= 1 &&
							Math.abs(((currentHouseNum+1) - this.houseNum2.intValue())) <= 1 
							)
						{
							h4.changeImageToBuilt();
							this.currentHouseNum++;
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							
							
							this.houseNum3.increment();
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
						}
					//or we can deselect it when there is only one house on the property.
					else if((currentHouseNum == 4) &&
							this.hasHotel1.boolValue() == false &&
							this.hasHotel2.boolValue() == false &&
							this.hasHotel3.boolValue() == false &&
							Math.abs(((currentHouseNum-1) - this.houseNum1.intValue())) <= 1 &&
							Math.abs(((currentHouseNum-1) - this.houseNum2.intValue())) <= 1 
							)
					{
							h4.changeImageToSale();
							this.currentHouseNum--;
							this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
							
							
							
							this.houseNum3.decrement();
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					}
				}
			}
		}
		if(e.getSource() == hotel){
			if(this.hasHotel == true){
				//CASE1: There are 2 properties of the color
				if(size == 2){
					if(this.propertyNumber == 0){
						//we can't build the first building if there already exists 2 houses(can do only when currentHouseNum is 1). 
						//if there is no house && the difference of these 2 houses is less than 2, we can build
						//&& the resulting cost doesnt exceed the player's cash
						if(this.hasHotel1.boolValue() == false && 
								this.houseNum1.intValue() == 4 &&
								this.houseNum2.intValue() == 4 
								)
						{
							hotel.changeImageToBuilt();
							//this.currentHouseNum++;
							//System.out.println(this.currentHouseNum);//test
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							//update the houseNumber
							
							this.hasHotel1.setBoolValue(true);
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + resultCash);
						}
						//or we can deselect it when there is only one house on the property.
						//&& it keeps the differece of houseNum <= 1
						//&& the resulting currentHouseNum won't be less than the minimum HouseNum
						else if(this.hasHotel1.boolValue() == true)
								//Math.abs(((currentHouseNum-1) - this.houseNum2.intValue())) <= 1 &&)
						{
								hotel.changeImageToSale();
								//this.currentHouseNum--;
								System.out.println(this.currentHouseNum);//test
								this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
								this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
								
								
									this.hasHotel1.setBoolValue(false);
								
								this.totalLabel.setText("Total cost: $" + totalGain.intValue());
								this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
						}
					}
				else if(this.propertyNumber == 1){
					//we can't build the first building if there already exists 2 houses(can do only when currentHouseNum is 1). 
					//if there is no house && the difference of these 2 houses is less than 2, we can build
					//&& the resulting cost doesnt exceed the player's cash
					if( this.hasHotel2.boolValue() == false && 
							this.houseNum1.intValue() == 4 &&
							this.houseNum2.intValue() == 4 
							)
					{
							hotel.changeImageToBuilt();
							//this.currentHouseNum++;
							System.out.println(this.currentHouseNum);//test
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							//update the houseNumber
							
							this.hasHotel2.setBoolValue((true));
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + resultCash);
					}
					//or we can deselect it when there is only one house on the property.
					//&& it keeps the differece of houseNum <= 1
					//&& the resulting currentHouseNum won't be less than the minimum HouseNum
					else if(this.hasHotel2.boolValue() == true){
								hotel.changeImageToSale();
								//this.currentHouseNum--;
								System.out.println(this.currentHouseNum);//test
								this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
								this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
								
								
								this.hasHotel2.setBoolValue(false);
								
								this.totalLabel.setText("Total cost: $" + totalGain.intValue());
								this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					}
				}
			}
			//CASE2: There are 3 properties of the color
			else if(size == 3){
				if(this.propertyNumber == 0){
					//if there is no house && the difference of these 2 houses is less than 2, we can build
					//&& the resulting cost doesnt exceed the player's cash
					if( this.hasHotel1.boolValue() == false && 
							this.houseNum1.intValue() == 4 &&
							this.houseNum2.intValue() == 4 &&
							this.houseNum3.intValue() == 4 
							)
						{
							hotel.changeImageToBuilt();
							//this.currentHouseNum++;
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							
							this.hasHotel1.setBoolValue(true);
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
						}
					//or we can deselect it when there is only one house on the property.
					else if(this.hasHotel1.boolValue() == true)
					{
							hotel.changeImageToSale();
							//this.currentHouseNum--;
							this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
							
							
							
							this.hasHotel1.setBoolValue(false);
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					}
				}
				else if(this.propertyNumber == 1){
					//if there is no house && the difference of these 2 houses is less than 2, we can build
					//&& the resulting cost doesnt exceed the player's cash
					if( this.hasHotel2.boolValue() == false && 
							this.houseNum1.intValue() == 4 &&
							this.houseNum2.intValue() == 4 &&
							this.houseNum3.intValue() == 4 
							)
						{
							hotel.changeImageToBuilt();
							//this.currentHouseNum++;
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							
							
							this.hasHotel2.setBoolValue(true);
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
						}
					//or we can deselect it when there is only one house on the property.
					else if(this.hasHotel2.boolValue() == true)
					{
							hotel.changeImageToSale();
							//this.currentHouseNum--;
							this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
							
							
							
							this.hasHotel2.setBoolValue(false);
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					}
				}
				else if(this.propertyNumber == 2){
					//if there is no house && the difference of these 2 houses is less than 2, we can build
					//&& the resulting cost doesnt exceed the player's cash
					if( this.hasHotel3.boolValue() == false && 
							this.houseNum1.intValue() == 4 &&
							this.houseNum2.intValue() == 4 &&
							this.houseNum3.intValue() == 4 
							)
						{
							hotel.changeImageToBuilt();
							//this.currentHouseNum++;
							this.totalGain.setIntValue(this.totalGain.intValue() - this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash -= this.Player.getBuildCost(this.nameOfProperty)/2;
							
							
							
							this.hasHotel3.setBoolValue(true);
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
						}
					//or we can deselect it when there is only one house on the property.
					else if(this.hasHotel3.boolValue() == true)
					{
							hotel.changeImageToSale();
							//this.currentHouseNum--;
							this.totalGain.setIntValue(this.totalGain.intValue() + this.Player.getBuildCost(this.nameOfProperty)/2);
							this.resultCash += this.Player.getBuildCost(this.nameOfProperty)/2;
							
							
							
							this.hasHotel3.setBoolValue(false);
							
							this.totalLabel.setText("Total cost: $" + totalGain.intValue());
							this.remainingCostLabel.setText("Cash remaining: $" + this.resultCash);
					}
				}
			}
		}
		}
			}
		
		else{
			if(e.getSource() == utilRailCheckBox)
				this.utilRailCheckBox.setSelected(true);
			if(e.getSource() == propCheckBox)
				propCheckBox.setSelected(true);
			
		}
			
			
	}
}

